<?php 
require_once 'BaseMySQLDAO.php';
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../Entity/Domain/PagecategoryDomain.php';
class PagecategoryDAO extends BaseMySQLDAO
{
	public function __construct($context) {
		parent::__construct($context, PagecategoryDomain::$CollectionName);
	}

	public function create($obj){
		$this->getContext()->getDBTransaction()->startTransaction();
		$inSQL = "INSERT INTO pagecategory(id,title,code,created_datetime,modified_datetime)
					VALUES	(
								".$obj->getId().",
								'".$obj->getTitle()."',
								'".$obj->getCode()."',
								'".$obj->getCreated_datetime()."',
								'".$obj->getModified_datetime()."'
							)";
		$this->getMySQLConnection()->mysqlData($inSQL);
		$this->getContext()->getDBTransaction()->closeTransaction();
	}

	public function deleteByOid($oid){
		$this->getContext()->getDBTransaction()->startTransaction();
		$inSQL = "DELETE FROM pagecategory WHERE id=".$oid;
		$this->getMySQLConnection()->mysqlData($inSQL);
		$this->getContext()->getDBTransaction()->closeTransaction();
	}

	public function update($obj){
		$this->getContext()->getDBTransaction()->startTransaction();
		$inSQL = "UPDATE pagecategory
				SET
					pagecategory.title = '".$obj->getTitle()."',
					pagecategory.code = '".$obj->getCode()."',
					pagecategory.created_datetime = '".$obj->getCreated_datetime()."',
					pagecategory.modified_datetime = '".$obj->getModified_datetime()."'
				 WHERE id=".$obj->getId();
		$this->getMySQLConnection()->mysqlData($inSQL);
		$this->getContext()->getDBTransaction()->closeTransaction();
	}

	public function findByOid($oid)
	{
		$pagecategoryDomain = null;
		$this->getContext()->getDBTransaction()->startTransaction();
		$inSQL = "SELECT * FROM pagecategory WHERE pagecategory.id = ".$oid;
		$res = $this->getMySQLConnection()->mysqlOneRow($inSQL);
		if($res)
		{
			$pagecategoryDomain = new PagecategoryDomain($res);
		}
		$this->getContext()->getDBTransaction()->closeTransaction();
		return $pagecategoryDomain;
	}

	public function findAll()
	{
		$pagecategoryDomainArr = array();
		$this->getContext()->getDBTransaction()->startTransaction();
		$inSQL = "SELECT * FROM pagecategory";
		$res = $this->getMySQLConnection()->mysqlData($inSQL);
		if($res)
		{
			while ($data = mysql_fetch_assoc($res))
			{
				$pagecategoryDomain = new PagecategoryDomain($data);
				$pagecategoryDomainArr[] = $pagecategoryDomain;
			}
		}
		$this->getContext()->getDBTransaction()->closeTransaction();
		return $pagecategoryDomain;
	}

}
?>